package com.headwind.controller;

import cn.hutool.core.lang.Dict;
import com.headwind.entity.HwMood;
import com.headwind.service.HwMoodService;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

/**
 * @author : Headwind
 * @version : 1.0
 * @date : Created in 2020/8/10
 * @description : 说说控制类
 */
@RestController
public class HwMoodController {
    private final HwMoodService moodService;

    public HwMoodController(HwMoodService moodService) {
        this.moodService = moodService;
    }

    /**
     * 查询所有说说
     *
     * @return 说说列表
     */
    @GetMapping("/moods")
    public CompletableFuture<Dict> findAllMood() {
        return CompletableFuture.supplyAsync(() ->
                moodService.findAllMoods());
    }

    /**
     * 查询用户所有说说
     *
     * @param userId 用户名
     * @return 说说列表
     */
    @GetMapping("/user/moods/{userId}")
    public CompletableFuture<Dict> findMoodsByUserId(@PathVariable String userId) {
        return CompletableFuture.supplyAsync(() ->
                moodService.findMoodsByUserId(userId));
    }

    /**
     * 保存发表的说说
     *
     * @param mood 说说内容
     * @return 状态信息
     */
    @PostMapping("/user/mood")
    public CompletableFuture<Dict> saveMood(@RequestBody HwMood mood) {
        return CompletableFuture.supplyAsync(() ->
                moodService.saveMood(mood));
    }

    /**
     * 删除特定的说说
     *
     * @param id 说说ID
     * @return 状态信息
     */
    @DeleteMapping("/mood/{id}")
    public CompletableFuture<Dict> deleteMood(@PathVariable String id) {
        return CompletableFuture.supplyAsync(() ->
                moodService.deleteMood(id));
    }

    /**
     * 更新发表的说说
     *
     * @param mood 说说内容
     * @return 状态信息
     */
    @PutMapping("/user/mood")
    public CompletableFuture<Dict> updateMood(@RequestBody HwMood mood) {
        return CompletableFuture.supplyAsync(() ->
                moodService.updateMood(mood));
    }
}
